import { Message } from 'element-ui';
import { request } from '../../common/request.js';
import { deepClone, formatMoney } from '../../common/utils.js';
import Contract from '../Component/Contract/page.vue'
export default {
    data() {
        return {
            sizeModel: 'large',
            form: {
                name: '',
                username: '',
                password: '',
                bank_name: '',
                bank_code: '',
                service_rate: '',
                sale_name: '',
                code: ''
            },
            isShowDialog: false,
            formS: {
                name: '',
                tax: '',
                tel: '',
                address: '',
                bank_name: '',
                bank_code: '',
                company_id: '',
            },
            formR: {
                express_address: '',
                express_name: '',
                express_tel: '',
                company_id: ''
            },
            formD: {
                company_id: ''
            },
            isShowDialogS: false,
            isShowDialogR: false,
            isShowDialogD: false,
            status: 3,
            param: {
                size: 10,
                page: 1,
            },
            total: 0,
            pageNum: [10,20,50],
            list: [],
            multipleSelection: [],
            percents: {},
            rates:{}
        }
    },

    components: {
        Contract
    },

    filters: {
        filterMoney(val) {
            return formatMoney(val);
        }
    },

    computed: {
        
    },
    methods: {
        submit() {
            // this.status++;
            request({
                url: 'addEnterprise',
                data: this.form,
                isShowLoading: true
            }).then(res => {
                if (res && res.data) {
                    this.formS.company_id = res.data.id;
                    this.formR.company_id = res.data.id;
                    this.formD.company_id = res.data.id;
                    this.status++;
                }
            })
        },
        pre() {
            this.status = this.status - 1;
        },
        toEnterPriseList() {
            this.$router.push({
                path: '/enterPriseList'
            })
        },
        submitS() {
            request({
                url: 'modifyInvoiceData',
                data: this.formS,
                isShowLoading: true
            }).then(res => {
                if (res) {
                    this.status++;
                }
            })
            // this.status++;
        },
        toInvoiceList() {
            
        },
        confirmR() {
            request({
                url: 'modifyInvoiceExpress',
                data: this.formR,
                isShowLoading: true
            }).then(res => {
                if (res) {
                    request({
                        url: 'getSupplierList',
                        params: this.param,
                        method: 'get',
                        isShowLoading: true
                    }).then(res => {
                        if (res && res.list && res.list.length) {
                            this.list = res.list;
                            this.status ++;
                        }
                    })
                }
            })
            // this.status++;
        },
        confirmD() {
            this.multipleSelection.forEach(item => {
                let percent = this.percents[item.id];
                this.formD[`percents[${item.id}]`] = percent;
            });
            request({
                url: 'addBizSupplier',
                data: this.formD,
                isShowLoading: true
            }).then(res => {
                if (res) {
                    Message({
                        message: '新增企业成功',
                        type: 'success'
                    });
                    this.$router.push({
                        path: '/enterPriseList'
                    });
                }
            })
            // this.status++;
        },
        handleSizeChange(val) {
            this.param.size = val;
            this.search();
        },
        pageSearch(val) {
            this.param.page = val;
            this.search()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        getDetails(info) {
            this.dialogParam = {
                enterPriseName: info.enterPriseName,
                enterPriseId: info.userId,
                availBalance: info.availBalance,
                bankAccount: '',
                freezeBalance: ''
            }
            this.isShowDialog = true;
        },
        getInvestDetail() {
            this.$router.push({
                path: '/investMoney',
                query: {
                    isShowRecords: 1
                }
            })
        },
        toTaskDetail() {
            this.$router.push({
                path: '/taskList',
                query: {
                    isShowTaskDetail: 1
                }
            })
        },
        // 给表头添加背景颜色
        getRowClass ({row, column, rowIndex, columnIndex}) {
            if (rowIndex === 0) {
                return 'height: 50px'
            } else {
                return ''
            }
        },
        handlePercents(id){
        	let num = this.percents[id]
        	
        	if(num < 1){
        		Message({
        			message:'分配比例过小',
        			type:'warning'
        		})
        	}else if(num>99){
        		Message({
        			message:'分配比例过大',
        			type:'warning'
        		})
        	}else{
        		let total = 0
        		for(let item in this.percents){
        			total += this.percents[item]*1
        		}
        		
        		if(total < 100){
        			Message({
	        			message:'未分配完全',
	        			type:'warning'
	        		})
        		}else if(total > 100){
        			Message({
	        			message:'不够分',
	        			type:'warning'
	        		})
        		}
        		
        	}
        	
        },
        handleTax(id){
        	
        }
    },
    mounted(){
        request({
            url: 'getSupplierList',
            params: this.param,
            method: 'get',
            isShowLoading: true
        }).then(res => {
            if (res && res.list && res.list.length) {
                this.list = res.list;
                // this.status ++;
            }
        })
        // this.search();
    }
}
